const {addClaims, getClaims, getClaimsBySalesMen, handleClaims, getClaimsById, changeClaims, getClaimsByState, deleteClaims, searchClaims} = require('../dao/claimsDao')
const { moveFiles, removeFiles } = require('../utils/handleFiles');

module.exports.addClaims = async (params) => {
  const data = await addClaims(params);
  if(data) {
    if(data.images) {
      data.images.forEach(item => {
        moveFiles({
          fromPath: './public/temp',
          toPath: './public/images',
          filename: item
        })
      })
      removeFiles('./public/temp');
      return {
        message: '增加成功',
        code: 1,
        data
      }
    }
  }
}

//获取所有理赔信息
module.exports.getClaims = async (params) => {
  const data = await getClaims(params);
  if(data) {
    return {
      message: '获取成功',
      code: 1,
      data
    }
  }
}


//根据state获取理赔
module.exports.getClaimsByState = async (params) => {
  const data = await getClaimsByState(params);
  if(data) {
    return {
      message: '获取成功',
      code: 1,
      data
    }
  }
}

//根据理赔id获取理赔订单
module.exports.getClaimsById = async (params) => {
  const data = await getClaimsById(params);
  if(data) {
    return {
      message: '获取成功',
      code: 1,
      data
    }
  }
}

//根据销售员获取理赔订单
module.exports.getClaimsBySalesMen = async (params) => {
  const data = await getClaimsBySalesMen(params);
  if(data) {
    return {
      message: '获取成功',
      code: 1
    }
  }
}

//处理理赔订单
module.exports.changeClaims = async (params) => {
  const data = await changeClaims(params);
  if(data) {
    return {
      message:'审核成功',
      code: 1
    }
  }
}

//根据销售员获取理赔订单
module.exports.handleClaims = async (params) => {
  const data = await handleClaims(params);
  if(data) {
    return {
      message: '处理成功',
      code: 1
    }
  }
}

//删除订单
module.exports.deleteClaims = async (params) => {
  const data = await deleteClaims(params);
  if(data) {
    return {
      code: 1,
      message: '删除成功',
    }
  }
}

//查询
module.exports.searchClaims = async (params) => {
  const data = await searchClaims(params);
  if(data) {
    return {
      code: 1,
      message: '获取成功',
      data
    }
  }
}

